package com.yunao.commons.serachcore.core.bean;

import com.yunao.service.report.bean.compare.ComparatorCubeByKey;
import com.yunao.service.report.bean.compare.ComparatorCubeByValue;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Cubes extends BaseEntities implements Serializable {

	private static final long serialVersionUID = 1L;

	private long total;
	private long size;
	private List<Cube> data;
	private List<Group> subs;

	public Cubes() {

	}

	public Cubes(long total) {
		this.total = total;
	}

	public Long getTotal() {
		return total;
	}

	public Long getSize() {
		return size;
	}

	public List<Cube> getData() {
		if (data == null) {
			return Collections.emptyList();
		}
		return data;
	}

	public void addData(Cube e) {
		if (data == null) {
			data = new ArrayList<>();
		}
		data.add(e);
		size++;
	}

	public List<Group> getSubs() {
		if (subs == null) {
			return Collections.emptyList();
		}
		return subs;
	}

	public void addSubs(Group e) {
		if (subs == null) {
			subs = new ArrayList<>();
		}
		subs.add(e);
	}

	public Cube get(int index) {
		return data.get(index);
	}

	public int size() {
		return data.size();
	}

	public void sortByKey() {
		Collections.sort(data, new ComparatorCubeByKey<Cube>());
	}

	public void sortByValue() {
		Collections.sort(data, new ComparatorCubeByValue<Cube>());
	}

	public void sortSubByKey() {
		for (int i = 0; i < data.size(); i++) {
			Cube bean = data.get(i);
			bean.sortByKey();
		}
	}

	public void sortSubByValue() {
		for (int i = 0; i < data.size(); i++) {
			Cube bean = data.get(i);
			bean.sortByValue();
		}
	}

	@Override
	public String toString() {
		return toString(total, size, data);
	}

}
